//
//  FANMainViewController.m
//  Weibo - OC
//
//  Created by user on 16/4/16.
//  Copyright © 2016年 user. All rights reserved.
//

#import "FANMainViewController.h"
#import "FANHomeTableViewController.h"
#import "FANMessageTableViewController.h"
#import "FANDiscoverTableViewController.h"
#import "FANProfileTableViewController.h"
#import "FANTabBar.h"
#import "FANComposeView.h"

@interface FANMainViewController ()

@end

@implementation FANMainViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    
    
    FANTabBar *tabBar = [[FANTabBar alloc] init];
    
    
//    tabBar.backBlock = 
    
    [tabBar setBackBlock:^{
        
        FANComposeView *composeView = [[FANComposeView alloc] init];
        
//        [self.view addSubview:composeView];
        
        [composeView show:self];
    }];
    
    [self setValue:tabBar forKey:@"tabBar"];
    
    [self setupChildVc];
}

- (void)setupChildVc{
    
    [self loadVcInfo:[[FANHomeTableViewController alloc] init] andTitle:@"首页" andImageName:@"tabbar_home"];
    
    [self loadVcInfo:[[FANMessageTableViewController alloc] init] andTitle:@"消息" andImageName:@"tabbar_message_center"];
    
    [self loadVcInfo:[[FANDiscoverTableViewController alloc] init] andTitle:@"发现" andImageName:@"tabbar_discover"];
    
    [self loadVcInfo:[[FANProfileTableViewController alloc] init] andTitle:@"我" andImageName:@"tabbar_profile"];
    
    
}

- (void)loadVcInfo:(UIViewController *)Vc andTitle:(NSString *)title andImageName:(NSString *)imageName{
    
    Vc.title = title;
    
    Vc.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    Vc.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    [Vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateSelected];
    
    [self addChildViewController:[[UINavigationController alloc] initWithRootViewController:Vc]];
    
}


@end
